
import java.awt.*;
import java.awt.event.*;


public class NumericFilter {
	Toolkit tk = Toolkit.getDefaultToolkit();
	boolean audio = true;
	
	public NumericFilter(Component comp){
		comp.addKeyListener(new KeyListener(){

			public void keyTyped(KeyEvent e) {
				if (e.isActionKey()) //ignoruje klawisze akcji
				return;
				if (isKeyValid(e))
					return;
				e.consume(); //filtruje nacisnieci klawisza
				if(audio)
					tk.beep();
			}

			public void keyPressed(KeyEvent e) {
				// TODO Auto-generated method stub
				
			}

			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}
	public boolean isKeyValid(KeyEvent e){
		char c = e.getKeyChar();
		return (Character.isDigit(c)) ||
		(c =='.') || (c==KeyEvent.VK_BACK_SPACE) || (c==KeyEvent.VK_DELETE);
	}


}
